﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace lcmyjobs.Web.Admin
{
    public partial class NewsTJ : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Application["webid"] != null)
                {
                    Bind(Convert.ToInt32(Application["webid"]));
                }
                
            }
        }

        public string GetStr(string str)
        {
            if (str.Length > 20)
            {
                return lcmyjobs.BLL.Tools.RemoveHtml(str,19) + "......";
            }
            else
            {
                return lcmyjobs.BLL.Tools.RemoveHtml(str, 19);
            }
        }

       

        private void Bind(int atid)
        {
            DataSet ds = new lcmyjobs.BLL.news().GetList(" atid=" + atid + "  and  ntid<>11 and ntid<>12 and ntid<>13 and ntid<>14 and ntid<>15 ");

            this.GridView1.DataSource = ds;
            this.GridView1.DataBind();

            if (ViewState["page"] != null)
            {
                this.GridView1.PageIndex = Convert.ToInt32(ViewState["page"]);
            }
            
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {

            this.GridView1.PageIndex = e.NewPageIndex;
            ViewState["page"] = e.NewPageIndex;

            if (Application["webid"] != null)
            {
                Bind(Convert.ToInt32(Application["webid"]));
            }
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName=="lbn_rm")
            {
                if (e.CommandArgument != null)
                {
                    int nid = Convert.ToInt32(e.CommandArgument);


                    if (new lcmyjobs.BLL.news().UpdateWhere("isrm", "1", nid.ToString()))
                    {
                        ViewState["page"] = this.GridView1.PageIndex;

                        Maticsoft.Common.MessageBox.Show(this,"标记热门文章成功！");
                        if (Application["webid"] != null)
                        {
                            Bind(Convert.ToInt32(Application["webid"]));
                        }
                    }
                }
               
            }

            if (e.CommandName == "lbn_tj")
            {
                if (e.CommandArgument != null)
                {
                    int nid = Convert.ToInt32(e.CommandArgument);


                    if (new lcmyjobs.BLL.news().UpdateWhere("istj", "1", nid.ToString()))
                    {
                        ViewState["page"] = this.GridView1.PageIndex;

                        Maticsoft.Common.MessageBox.Show(this, "标记推荐文章成功！");
                        if (Application["webid"] != null)
                        {
                            Bind(Convert.ToInt32(Application["webid"]));
                        }

                    }
                }

            }

            if (e.CommandName == "lbn_cxtj")
            {

                if (e.CommandArgument != null)
                {
                    int nid = Convert.ToInt32(e.CommandArgument);


                    if (new lcmyjobs.BLL.news().UpdateWhere("istj", "0", nid.ToString()))
                    {
                        ViewState["page"] = this.GridView1.PageIndex;

                        Maticsoft.Common.MessageBox.Show(this, "撤销推荐文章标记成功！");
                        if (Application["webid"] != null)
                        {
                            Bind(Convert.ToInt32(Application["webid"]));
                        }
                    }
                }
            }
            if (e.CommandName == "lbn_cxrm")
            {
                if (e.CommandArgument != null)
                {
                    int nid = Convert.ToInt32(e.CommandArgument);


                    if (new lcmyjobs.BLL.news().UpdateWhere("isrm", "0", nid.ToString()))
                    {
                        ViewState["page"] = this.GridView1.PageIndex;

                        Maticsoft.Common.MessageBox.Show(this, "撤销热门文章标记成功！");
                        if (Application["webid"] != null)
                        {
                            Bind(Convert.ToInt32(Application["webid"]));
                        }
                    }
                }
            }
        }
    }
}